import { ref, reactive } from 'vue'
import { ORDER_STATUS } from '@/utils/dictionary'
import { getDeptList } from '@/api/org-manage/depart-manage/index'

// 部门列表
const deptList = ref([])

export const search = reactive({
  search: [
    {
      label: '工单编号',
      key: 'code',
      props: {
        placeholder: '请输入工单编号'
      }
    },
    {
      label: '工单状态',
      type: 'select',
      key: 'status',
      props: {
        placeholder: '请选择工单状态',
        options: ORDER_STATUS
      }
    },
    {
      label: '创建部门',
      type: 'select',
      key: 'inspectionLine',
      props: {
        placeholder: '请选择创建部门',
        options: deptList
      }
    },
    {
      label: '工单生成时间',
      type: 'date',
      key: 'createTime',
      props: {
        type: 'datetimerange',
        format: 'yyyy-MM-dd HH:mm:ss'
      }
    }
  ]
})

// 获取部门列表
export const getDeptInfo = async function(id) {
  const { data } = await getDeptList(id)
  deptList.value = data?.map(it => ({
    ...it,
    label: it.name,
    value: it.id
  }))
}
